<?php

class AdministrativosController extends AppController {

    public $components = array('Paginator');
    public $uses = array('User');
    public $layout = 'sib';

    public function index() {
        $administrativos = $this->User->find('all', array(
            'recursive' => -1
        ));
        $this->set(compact('administrativos'));
    }

    public function insertar() {
        if ($this->request->is('post')) {
            $this->User->create();
            if ($this->User->save($this->request->data)) {
                $this->Session->setFlash('Se guardo correctamente',mensajeBueno);
                $this->redirect(array('action' => 'index'), null, true);
            } else {
                $this->Session->setFlash('Error al guardar',mensajeError);
            }
        }
    }

    function editar($id = null) {

        $this->User->id = $id;
        if (!$this->User->exists()) {
            throw new NotFoundException(__('Invalido'));
        }
        if (!empty($this->request->data)) {
            //debug($this->request->data);exit;
            $this->User->id = $id;
            if ($this->User->save($this->request->data)) {
                $this->Session->setFlash('se guardo correctamente',mensajeBueno);
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash('Error. Intentelo de nuevo',mensajeError);
                $this->redirect(array('action' => 'index'));
            }
        } else {
            $this->request->data = $this->User->read(null, $id);
        }
    }

    function delete($id) {
        if ($this->request->data('post')) {
            throw new MethodNotAllowedException();
        }
        if ($this->User->delete($id)) {
            $this->Session->setFlash($id . 'Ha sido eliminado',mensajeBueno);
            $this->redirect(array('action' => 'index'));
        }
    }

}

?>
